<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>平台概览</title>
    <link rel="shortcut icon" href="img/favicon.ico"/>
    <style>
        body{height:100%;background:#060f4c; margin: 0;
            /*background:-webkit-gradient(linear, 0 0, 0 bottom, from(#0D1D3F), to(rgba(13,67,127, 0.7)));*/
        }
        .fl{float:left;}
        .fr{float:right;}
        .clear{clear:both;}
        ul{padding:0;}
        li{list-style:none}
        a{text-decoration : none}

        .header{width:100%;color:#ddd;text-align:center;height:60px;line-height:60px;font-size:20px;letter-spacing:3px;}
        .center{position:absolute;width:100%;top:60px;bottom:0;}

        #container1{height: 49%;width:25%;}
        #container2{height: 49%;width:25%;}
        #container3{height: 49%;width:25%;}
        #container4{height: 49%;width:25%;}
        #container5{height: 49%;width:25%;}
        #container6{height: 49%;width:25%;}
        #container7{height: 49%;width:25%;}
        #container8{height: 49%;width:25%;}
    </style>
</head>
<body>
    <div class="header">
        <b>数据概览</b>
    </div>
    <div class="center">
        <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
        <div id="container1" class="fl"></div>
        <div id="container2" class="fl"></div>
        <div id="container3" class="fl"></div>
        <div id="container4" class="fl"></div>
        <div id="container5" class="fl"></div>
        <div id="container6" class="fl"></div>
        <div id="container7" class="fl"></div>
        <div id="container8" class="fl"></div>
        <div class="clear"></div>
    </div>
</body>
<script src="js/jquery.min.js"></script>
<script src="js/echarts.js"></script>
<script src="js/china.js"></script>
<script src="js/dataTool.js"></script>
<script src="js/citymap.js"></script>
<script>
    var agent_id = window.location.href.split('?')[1].split('=')[1].split('&')[0];
    var merchant_id = window.location.href.split('?')[1].split('=')[2].split('&')[0];
    var user_type = window.location.href.split('?')[1].split('=')[3];//10为代理商 20为商户
    $.ajax({
        url:"http://water.ahtyt.com/one/api/v2/dashborad/dashboard",
        type:'get',
        async:false,
        data:{ 'agent_id':agent_id,'merchant_id':merchant_id,'user_type':user_type },
        success:function(e){
            console.log(e)
            res = e.response.data;
            // console.log(e.response.data);
            //-------------合作伙伴及工具数 container2----------------------------
            if(res.merchant_count==undefined){
                merchant_count = 0;
            }else{
                merchant_count = res.merchant_count;//商户数量
            }
            if(res.store_count==undefined){
                store_count = 0;
            }else{
                store_count = res.store_count;//门店数量
            }
            if(res.casher_count==undefined){
                casher_count = 0;
            }else{
                casher_count = res.casher_count;//收银员数量
            }
            // if(res.device_count==undefined){
            //     device_count = 0;
            // }else{
            //     device_count = res.device_count;//终端数量
            // }
            if(res.pay_sty_count==undefined){
                device_count = 0;
            }else {
                if (res.pay_sty_count[0].all_ount == undefined) {
                    device_count = 0;
                } else {
                    device_count = res.pay_sty_count[0].all_ount;//终端数量
                }
            }
            //-------------终端类型占比 container3---------------------------------
            // if(res.kuai_count==undefined){
            //     kuai_count = 0;
            // }else{
            //     kuai_count = res.kuai_count;//快乐收
            // }
            // if(res.oc_count==undefined){
            //     oc_count = 0;
            // }else{
            //     oc_count = res.oc_count;//一码付
            // }
            // if(res.android_count==undefined){
            //     android_count = 0;
            // }else{
            //     android_count = res.android_count;//安卓
            // }
            // other_count = device_count*1-kuai_count*1-oc_count*1-android_count*1;//其他
            if(res.pay_sty_count==undefined){
                kuaile_count = 0;
                yimafu_count = 0;
                xzg_count = 0;
                pos_count = 0;
                other_count = 0;
            }else{
                if(res.pay_sty_count[0].kuaile_count==undefined){
                    kuaile_count = 0;
                }else{
                    kuaile_count = res.pay_sty_count[0].kuaile_count;//快乐收
                }
                if(res.pay_sty_count[0].yimafu_count==undefined){
                    yimafu_count = 0;
                }else{
                    yimafu_count = res.pay_sty_count[0].yimafu_count;//一码付
                }
                if(res.pay_sty_count[0].xzg_count==undefined){
                    xzg_count = 0;
                }else{
                    xzg_count = res.pay_sty_count[0].xzg_count;//炫掌柜
                }
                if(res.pay_sty_count[0].pos_count==undefined){
                    pos_count = 0;
                }else{
                    pos_count = res.pay_sty_count[0].pos_count;//智能pos
                }
                if(res.pay_sty_count[0].other_count==undefined){
                    other_count = 0;
                }else{
                    other_count = res.pay_sty_count[0].other_count;//其他
                }
            }
            //-------------支付渠道使用率 container4---------------------------------
            c_list = res.c_list;
            c_list_name = ['现金','会员卡','银联','翼支付','微信','支付宝'];//渠道名称数组 10 20 30 40
            c_list_value =[0,0,0,0,0,0];//渠道使用率数组
            c_list_count = 0;//渠道使用总数
            if(c_list!=undefined){
                    for(var i=0;i<c_list.length;i++){
                        c_list_count = c_list_count*1+c_list[i]['count']*1;
                    }
                    // console.log(c_list[i]['count']/c_list_count)
                    for(var i=0;i<c_list.length;i++){
                        if(c_list[i]['_id']=='10'){
                            c_list_value[5]=(c_list[i]['count']/c_list_count).toFixed(2);
                        }else if(c_list[i]['_id']=='20'){
                            c_list_value[4]=(c_list[i]['count']/c_list_count).toFixed(2);
                        }else if(c_list[i]['_id']=='30'){
                            c_list_value[3]=(c_list[i]['count']/c_list_count).toFixed(2);
                        }else if(c_list[i]['_id']=='40'){
                            c_list_value[2]=(c_list[i]['count']/c_list_count).toFixed(2);
                        }else if(c_list[i]['_id']=='50'){
                            c_list_value[1]=(c_list[i]['count']/c_list_count).toFixed(2);
                        }else if(c_list[i]['_id']=='60'){
                            c_list_value[0]=(c_list[i]['count']/c_list_count).toFixed(2);
                        }
                    }
            }
            //--------------近七天交易数据展示 container5---------------------------
            t_list = res.t_list;
            t_list_time = [];//时间数组
            t_list_count = [];//交易笔数数组
            t_list_price = [];//交易金额数组
            if(t_list!=undefined) {
                for (var j = 0; j < t_list.length; j++) {
                    t_list_time.push(t_list[j]['order_date']);
                    t_list_count.push(t_list[j]['total_count']);
                    t_list_price.push(t_list[j]['total_price']);
                }
            }
            //--------------近半年月交易额 和 近半年月交易笔数 container6------------
            half_year = res.half_year;
            half_year_time = [];//近半年时间数组
            half_year_count = [];//近半年年交易笔数数组
            half_year_price = [];//近半年交易金额数组
            half_year_price_count = 0;//近半年月交易额总计
            half_year_num_count = 0;//近半年月交笔数额总计
            half_year_price_ratio = [];//近半年月交金额占比
            half_year_num_ratio = [];//近半年月交笔数占比
            if(half_year!=undefined) {
                for (var a = 0; a < half_year.length; a++) {
                    half_year_price_count = half_year_price_count * 1 + half_year[a]['total_price'] * 1;
                    half_year_num_count = half_year_num_count * 1 + half_year[a]['total_num'] * 1;
                }
                for (var k = 0; k < half_year.length; k++) {
                    half_year_time.push(half_year[k]['order_date']);
                    half_year_count.push(half_year[k]['total_num']);
                    half_year_price.push(half_year[k]['total_price']);
                    half_year_price_ratio.push((half_year[k]['total_price'] / half_year_price_count).toFixed(2) * 10 * 10);
                    half_year_num_ratio.push((half_year[k]['total_num'] / half_year_num_count).toFixed(2) * 10 * 10);
                }
            }

            //----------------------------------------------------------
            if(user_type=='10'){
                //行业使用占比
                h_list = res.h_list;
                h_list_c = 0;
                h_list_y = 0;
                h_list_x = 0;
                h_list_f = 0;
                h_list_q = 0;
                if(h_list!=undefined) {
                    h_list_count = h_list['c'] * 1 + h_list['y'] * 1 + h_list['x'] * 1 + h_list['f'] * 1 + h_list['q'] * 1;
                    h_list_c = (h_list['c'] / h_list_count).toFixed(2);
                    h_list_y = (h_list['y'] / h_list_count).toFixed(2);
                    h_list_x = (h_list['x'] / h_list_count).toFixed(2);
                    h_list_f = (h_list['f'] / h_list_count).toFixed(2);
                    h_list_q = (h_list['q'] / h_list_count).toFixed(2);
                    // console.log(h_list_c)
                }
            }else{
                //-------------门店按累计交易额排名（只显示前五名）container8--------------------
                store_ranking = res.store_ranking;
                store_ranking_name = [];
                store_ranking_price = [];
                if(store_ranking!=undefined) {
                    for (var b = 0; b < store_ranking.length; b++) {
                        store_ranking_name.push(store_ranking[b]['store_name']);
                        store_ranking_price.push(store_ranking[b]['total_price']);
                    }
                }
            }
            
            

        }
    });

</script>
<script src="js/container1.js"></script>
<script src="js/container2.js"></script>
<script src="js/container3.js"></script>
<script src="js/container4.js"></script>
<script src="js/container5.js"></script>
<script src="js/container6.js"></script>
<script src="js/container7.js"></script>
<script src="js/container8.js"></script>

</html>